def u ():
    d = input().split()
    if len(d) != 3:
        return "Wrong input"

    f = {

    "zero": 0, "one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9
    }

    g  = f.get (d [0], 0) * 100+ f. get (d [1], 0) * 10 +f.get(d[2], 0)
    if not 100 <= g <= 999:
        return "Wrong input"

    def h(n):
        if n <= 1:
            return False
        for i in range(2, int(n ** 0.5) + 1):
            if n % i== 0:
                return False
        return True

    q = w = g

    while True:
        if h (q):
            return q
        if h (w):
            return w

        q -= 1

        w += 1

print(u())
